﻿using System;
using System.Xml.Serialization;
using System.ComponentModel;

namespace Microsoft.WowAddonStudio.Lua.Model
{
    /// <summary>
    /// A Lua function.
    /// </summary>
    [XmlType(Namespace = "http://schemas.microsoft.com/aos/2008/xmldoc")]
    public class Function : Declaration
    {
        /// <summary>
        /// Gets the type of the function.
        /// </summary>
        [XmlAttribute("type")]
        [DefaultValue(LuaType.Function)]
        public override LuaType Type
        {
            get { return LuaType.Function; }
            set
            {
                if (value != LuaType.Function)
                    throw new InvalidOperationException("The type is not allowed to be set to other than Function.");
            }
        }

        /// <summary>
        /// Gets or sets the parameters of the function.
        /// </summary>
        [XmlElement("param", typeof(Parameter))]
        [XmlElement("paramchoice", typeof(ParameterChoice))]
        public Parameter[] Parameters { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the function is a variadic function
        /// (a function that can have variable number of arguments).
        /// </summary>
        [XmlAttribute("variadic")]
        [DefaultValue(false)]
        public bool Variadic { get; set; }

        /// <summary>
        /// Gets or sets the return values of the function.
        /// </summary>
        [XmlElement("return")]
        public ReturnValue[] Returns { get; set; }

    }
}
